<html>
<head>
<title>Example of Click-to-Call</title>
</head>
<body>
<?

$strHost = "127.0.0.1";
$strUser = "admin";
$strSecret = "voiper";
$strWaitTime = "30";
$strPriority = "1";
$strMaxRetry = "2";

$strExten = $_POST['txtphonenumber'];
$strChannel = $_POST['strChannel'];
$strContext = $_POST['strContext'];

$strCallerId = "Click-to-Call <$strExten>";

if (is_numeric($strExten))
{
$oSocket = fsockopen($strHost, 5038, $errnum, $errdesc) or die("Connection to host failed");
fputs($oSocket, "Action: login\r\n");
fputs($oSocket, "Events: off\r\n");
fputs($oSocket, "Username: $strUser\r\n");
fputs($oSocket, "Secret: $strSecret\r\n\r\n");
fputs($oSocket, "Action: originate\r\n");
fputs($oSocket, "Channel: $strChannel\r\n");
fputs($oSocket, "WaitTime: $strWaitTime\r\n");
fputs($oSocket, "CallerId: $strCallerId\r\n");
fputs($oSocket, "Exten: $strExten\r\n");
fputs($oSocket, "Context: $strContext\r\n");
fputs($oSocket, "Priority: $strPriority\r\n\r\n");
fputs($oSocket, "Action: Logoff\r\n\r\n");
fclose($oSocket);
?>
<p>
<table align="center" width="300" border="1" bordercolor="#000000" cellpadding="3" cellspacing="0">
	<tr><td>
	<center><font size="2" face="verdana,arial,georgia" color="#000000">If your phone not ringing in 2 minutes, a error occured during the call transfer on your extension.<br><br><a href="<? echo $_SERVER['PHP_SELF'] ?>">Riprova</a></font></center>
	</td></tr>
</table>
</p>
<?
}
else
{
?>
<p>
<table align="center" width="300" border="1" bordercolor="#000000" cellpadding="3" cellspacing="0">
	<tr><td>
	<form action="<? echo $_SERVER['PHP_SELF'] ?>" method="post">

		<center><font size="2" face="verdana,arial,georgia" color="#000000">Please type the destination Phone number<br>and include the Outbound Prefix:</font>
		<input type="text" size="20" maxlength="30" name="txtphonenumber"><br><br>
		<font size="2" face="verdana,arial,georgia" color="#000000">This is the call Context<br>(example: from-internal):</font>
		<input type="text" size="20" maxlength="30" name="strContext" value="from-internal"><br><br>
		<font size="2" face="verdana,arial,georgia" color="#000000">Please type your extension number<br>(example: SIP/1000, IAX2/1000):</font>
		<input type="text" size="20" maxlength="30" name="strChannel">&nbsp;<input type="submit" value="Call"></center>
	</form>
	</td></tr>
</table>
</p>
<?
}
?>
</body>
</html>
